export class DictArray {
  values: Record<string, any[]> = {}
  constructor() {}
  add(key: string, val: any) {
    this.getValuesAtKey(key).push(val)
  }
  remove(key: string, e: any) {
    const s = this.values[key]
    if (s) {
      const index = s.indexOf(e)
      index > -1 && s.splice(index, 1)
    }
  }
  getValuesAtKey(key: string) {
    const val = this.values[key] || []
    this.values[key] = val
    return val
  }
  valuesPerKey(key: string) {
    return this.getValuesAtKey(key).length
  }
  get keys() {
    return Object.keys(this.values)
  }
}
export function removeArrayItem(list: any[], item: any) {
  if (0 !== list.length)
    for (let i = 0; i < list.length; i++) {
      list[i] === item && list.splice(i, 1)
    }
}
